<template>
  <div v-loading="loading">
    <div class="video_title">
      <van-icon name="arrow-left" class="icon" @click="goBack" />
      <p v-if="!titleName">专项练习</p>
      <p v-else-if="!disabled && usererror != '错题集'">
        <van-count-down
          :time="time"
          format="mm:ss"
          @change="timeChange"
          ref="time"
          style="color: #fff"
          @finish="finishTime"
        />
      </p>
      <p v-if="usererror == '错题集'">
        {{ usererror }}
      </p>
      <van-button
        v-if="$route.query.titleName != '正式考试'"
        @click="goFeedback"
        style="
          position: absolute;
          right: 0.93rem;
          width: 3.78rem;
          height: 1.4rem;
          border-radius: 1rem;
          padding: 0;
        "
        class="feedback"
        type="default"
        >问题反馈</van-button
      >
    </div>
    <div
      style="
        padding: 0.75rem;
        background: #fff;
        height: calc(100vh - 94px);
        overflow-y: auto;
        overflow-x: hidden;
      "
    >
      <div
        class="titleBox"
        :style="!Current.stem_img ? 'margin-bottom:2.125rem;' : ''"
      >
        <span
          ><p>{{ qtype }}</p>
          {{ Current.stem }}</span
        >
      </div>
      <div
        style="
          line-height: 8.75rem;
          display: inline-block;
          height: 8.75rem;
          margin-bottom: 2.125rem;
        "
        v-if="Current.stem_img"
      >
        <img
          :src="Current.stem_img"
          @click="openImg([Current.stem_img])"
          style="height: 100%"
          alt=""
        />
      </div>
      <div style="margin-left: 5px">
        <van-checkbox-group
          v-model="checkList"
          v-if="qtype == '多选'"
          :disabled="disabled"
          @change="danChange(Current)"
        >
          <div v-for="(item, index) in Current.tiList" :key="index">
            <van-checkbox v-if="item.content" :name="item.cred">
              <span style="padding: 6px 0; display: inline-block"
                >{{ item.content
                }}<img
                  v-if="item.content_img"
                  style="max-width: 100px; max-height: 100px"
                  :src="item.content_img"
                  alt=""
              /></span>
              <template #icon="props">
                <template v-if="props.checked">
                  <img
                    class="img-icon"
                    v-if="!disabled"
                    :src="require(`@/assets/mobile/exam/${item.cred}-O.png`)"
                  />
                  <img
                    class="img-iconA"
                    v-else
                    :src="
                      errORpass
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/error.png`)
                    "
                  />
                </template>
                <template v-else>
                  <img
                    class="img-icon"
                    v-if="!disabled"
                    :src="require(`@/assets/mobile/exam/${item.cred}.png`)"
                  />
                  <img
                    :class="
                      daan && Current.answer == item.cred
                        ? 'img-iconA'
                        : 'img-icon'
                    "
                    v-else
                    :src="
                      daan && Current.answer == item.cred
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/${item.cred}.png`)
                    "
                  />
                </template>
              </template>
            </van-checkbox>
          </div>
        </van-checkbox-group>
        <van-radio-group
          v-model="daan"
          v-if="qtype == '单选'"
          @change="danChange(Current)"
          :disabled="disabled"
        >
          <!--  -->
          <div v-for="(item, index) in Current.tiList" :key="index">
            <van-radio v-if="item.content" :name="item.cred">
              <span style="padding: 6px 0; display: inline-block"
                >{{ item.content
                }}<img
                  v-if="item.content_img"
                  style="max-width: 100px; max-height: 100px"
                  :src="item.content_img"
                  alt=""
              /></span>
              <template #icon="props">
                <template v-if="props.checked">
                  <img
                    class="img-icon"
                    v-if="!disabled"
                    :src="require(`@/assets/mobile/exam/${item.cred}-O.png`)"
                  />
                  <img
                    class="img-iconA"
                    v-else
                    :src="
                      errORpass
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/error.png`)
                    "
                  />
                </template>
                <template v-else>
                  <img
                    class="img-icon"
                    v-if="!disabled"
                    :src="require(`@/assets/mobile/exam/${item.cred}.png`)"
                  />
                  <img
                    :class="
                      daan && Current.answer == item.cred
                        ? 'img-iconA'
                        : 'img-icon'
                    "
                    v-else
                    :src="
                      daan && Current.answer == item.cred
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/${item.cred}.png`)
                    "
                  />
                </template>
              </template>
            </van-radio>
          </div>
        </van-radio-group>
        <van-radio-group
          v-model="daan"
          v-if="qtype == '判断'"
          @change="danChange(Current)"
          :disabled="disabled"
        >
          <template v-if="!disabled">
            <van-radio name="正确" class="pd"> 正确 </van-radio>
            <van-radio name="错误" class="pd"> 错误 </van-radio>
          </template>
          <template v-else>
            <van-radio name="正确" class="pd">
              正确
              <template #icon="props">
                <template v-if="props.checked">
                  <img
                    class="img-iconA"
                    :src="
                      errORpass
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/error.png`)
                    "
                  />
                </template>
                <template v-else>
                  <img
                    :class="'img-iconA'"
                    :src="
                      daan && Current.answer == '正确'
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/PD.png`)
                    "
                  />
                </template>
              </template>
            </van-radio>
            <van-radio name="错误" class="pd">
              错误
              <template #icon="props">
                <template v-if="props && props.checked">
                  <img
                    class="img-iconA"
                    :src="
                      errORpass
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/error.png`)
                    "
                  />
                </template>
                <template v-else>
                  <img
                    :class="'img-iconA'"
                    :src="
                      daan && Current.answer == '错误'
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/PD.png`)
                    "
                  />
                </template>
              </template>
            </van-radio>
          </template>
        </van-radio-group>
        <div v-if="Current.qtype == '案例'">
          <div
            v-for="itemS in Current.children"
            :key="itemS.id"
            style="margin-bottom: 28px"
            v-show="!itemS.noerror"
          >
            <div
              class="titleBox"
              :style="!itemS.stem_img ? 'margin-bottom:2.125rem;' : ''"
            >
              <span
                ><p>{{ itemS.qtype }}</p>
                {{ itemS.stem }}</span
              >
            </div>
            <div
              style="
                line-height: 8.75rem;
                display: inline-block;
                height: 8.75rem;
                margin-bottom: 2.125rem;
              "
              v-if="itemS.stem_img"
            >
              <img :src="itemS.stem_img" style="height: 100%" alt="" />
            </div>
            <div style="margin-left: 5px">
              <van-checkbox-group
                v-model="itemS.checkList"
                v-if="itemS.qtype == '多选'"
                :disabled="disabled"
                @change="danChange({ pid: Current.id, ...itemS })"
              >
                <div v-for="(item, index) in itemS.childrenti" :key="index">
                  <van-checkbox v-if="item.content" :name="item.cred">
                    <img
                      v-if="item.content_img"
                      style="max-width: 100px; max-height: 100px"
                      :src="item.content_img"
                      alt=""
                    />
                    <span v-else>{{ item.content }}</span>
                    <template #icon="props">
                      <template v-if="props.checked">
                        <img
                          class="img-icon"
                          v-if="!disabled"
                          :src="
                            require(`@/assets/mobile/exam/${item.cred}-O.png`)
                          "
                        />
                        <img
                          class="img-iconA"
                          v-else
                          :src="
                            errORpass
                              ? require(`@/assets/mobile/exam/pass.png`)
                              : require(`@/assets/mobile/exam/error.png`)
                          "
                        />
                      </template>
                      <template v-else>
                        <img
                          class="img-icon"
                          v-if="!disabled"
                          :src="
                            require(`@/assets/mobile/exam/${item.cred}.png`)
                          "
                        />
                        <img
                          :class="
                            daan && Current.answer == item.cred
                              ? 'img-iconA'
                              : 'img-icon'
                          "
                          v-else
                          :src="
                            daan && Current.answer == item.cred
                              ? require(`@/assets/mobile/exam/pass.png`)
                              : require(`@/assets/mobile/exam/${item.cred}.png`)
                          "
                        />
                      </template>
                    </template>
                  </van-checkbox>
                </div>
              </van-checkbox-group>
              <van-radio-group
                v-model="itemS.uanswer"
                v-if="itemS.qtype == '单选'"
                @change="danChange({ pid: Current.id, ...itemS })"
                :disabled="disabled"
              >
                <!--  -->
                <div v-for="(item, index) in itemS.childrenti" :key="index">
                  <van-radio v-if="item.content" :name="item.cred">
                    <img
                      v-if="item.content_img"
                      style="max-width: 100px; max-height: 100px"
                      :src="item.content_img"
                      alt=""
                    />
                    <span v-else>{{ item.content }}</span>
                    <template #icon="props">
                      <template v-if="props.checked">
                        <img
                          class="img-icon"
                          v-if="!disabled"
                          :src="
                            require(`@/assets/mobile/exam/${item.cred}-O.png`)
                          "
                        />
                        <img
                          class="img-iconA"
                          v-else
                          :src="
                            errORpass
                              ? require(`@/assets/mobile/exam/pass.png`)
                              : require(`@/assets/mobile/exam/error.png`)
                          "
                        />
                      </template>
                      <template v-else>
                        <img
                          class="img-icon"
                          v-if="!disabled"
                          :src="
                            require(`@/assets/mobile/exam/${item.cred}.png`)
                          "
                        />
                        <img
                          :class="
                            daan && Current.answer == item.cred
                              ? 'img-iconA'
                              : 'img-icon'
                          "
                          v-else
                          :src="
                            daan && Current.answer == item.cred
                              ? require(`@/assets/mobile/exam/pass.png`)
                              : require(`@/assets/mobile/exam/${item.cred}.png`)
                          "
                        />
                      </template>
                    </template>
                  </van-radio>
                </div>
              </van-radio-group>
              <van-radio-group
                v-model="itemS.uanswer"
                v-if="itemS.qtype == '判断'"
                @change="danChange({ pid: Current.id, ...itemS })"
                :disabled="disabled"
              >
                <template v-if="!disabled">
                  <van-radio name="正确" class="pd"> 正确 </van-radio>
                  <van-radio name="错误" class="pd"> 错误 </van-radio>
                </template>
                <template v-else>
                  <van-radio name="正确" class="pd">
                    正确
                    <template #icon="props">
                      <template v-if="props.checked">
                        <img
                          class="img-iconA"
                          :src="
                            errORpass
                              ? require(`@/assets/mobile/exam/pass.png`)
                              : require(`@/assets/mobile/exam/error.png`)
                          "
                        />
                      </template>
                      <template v-else>
                        <img
                          :class="'img-iconA'"
                          :src="
                            daan && Current.answer == '正确'
                              ? require(`@/assets/mobile/exam/pass.png`)
                              : require(`@/assets/mobile/exam/PD.png`)
                          "
                        />
                      </template>
                    </template>
                  </van-radio>
                  <van-radio name="错误" class="pd">
                    错误
                    <template #icon="props">
                      <template v-if="props && props.checked">
                        <img
                          class="img-iconA"
                          :src="
                            errORpass
                              ? require(`@/assets/mobile/exam/pass.png`)
                              : require(`@/assets/mobile/exam/error.png`)
                          "
                        />
                      </template>
                      <template v-else>
                        <img
                          :class="'img-iconA'"
                          :src="
                            daan && Current.answer == '错误'
                              ? require(`@/assets/mobile/exam/pass.png`)
                              : require(`@/assets/mobile/exam/PD.png`)
                          "
                        />
                      </template>
                    </template>
                  </van-radio>
                </template>
              </van-radio-group>
              <div class="daan_box" v-if="isDaAn">
                <span>正确答案:{{ itemS.answer }}</span>
                <p v-if="itemS.analysis">解析:{{ itemS.analysis }}</p>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div
        v-if="
          this.titleName != '正式考试' &&
          this.$route.query.daan == '显示' &&
          Current.qtype == '多选' &&
          !disabled
        "
        class="button_box"
      >
        <van-button
          round
          type="info"
          id="DXcommit"
          @click="danChange(Current, 'commit')"
          >提交</van-button
        >
      </div>
      <div class="button_box">
        <van-button
          round
          type="info"
          @click="changeClick('end')"
          v-if="enddisabled"
          >上一题</van-button
        >
        <!-- {{num}} -->
        <van-button
          round
          type="info"
          @click="changeClick('add')"
          v-if="downdisabled"
          >下一题</van-button
        >
      </div>

      <div class="daan_box" v-if="isDaAn && Current.qtype != '案例'">
        <span>正确答案:{{ Current.answer }}</span>
        <p v-if="Current.analysis">解析:{{ Current.analysis }}</p>
      </div>
    </div>
    <div class="foot_box">
      <div
        @click="
          () => {
            this.show = !this.show;
          }
        "
      >
        <van-icon name="qr" />
        <span>{{ TIXU }}/{{ Ti.length }}</span>
      </div>
      <div v-if="!titleName">
        <van-button round type="danger" size="small" @click="again"
          >重做</van-button
        >
      </div>
      <div
        @click="CollectionClick(DQTI)"
        v-if="
          (!titleName || titleName == '模拟考试') &&
          !this.usererror &&
          !disabled
        "
      >
        <van-icon name="star" v-if="isYes" />
        <van-icon name="star-o" v-else />
        <span>{{ isYes ? "取消收藏" : "收藏" }}</span>
      </div>
      <div v-if="this.usererror == '错题集'">
        <van-button round type="warning" size="small" @click="delerror(DQTI)"
          >移出错题库</van-button
        >
      </div>
      <div v-if="this.usererror == '收藏'">
        <van-button round type="warning" size="small" @click="delSc(DQTI)"
          >移出收藏</van-button
        >
      </div>
      <div>
        <van-button
          round
          type="warning"
          size="small"
          v-if="!titleName && !isDaAn"
          @click="beiti"
        >
          背题模式
        </van-button>
        <van-button
          round
          type="primary"
          v-if="!titleName && isDaAn"
          @click="zuoti"
          size="small"
          >做题模式</van-button
        >
      </div>
      <div>
        <van-button
          round
          type="danger"
          size="small"
          @click="commit"
          v-if="!titleName"
          >退出</van-button
        >
        <van-button
          round
          type="danger"
          size="small"
          @click="commit"
          v-else-if="titleName && !disabled"
          >提交试卷</van-button
        >
        <van-button round type="danger" size="small" @click="goBack" v-else
          >退出</van-button
        >
      </div>
    </div>
    <van-action-sheet
      v-model="show"
      title=""
      :closeable="false"
      id="rootBox"
      :transition-appear="true"
      :lazy-render="false"
    >
      <div
        style="
          width: 100%;
          height: 3.19rem;
          display: flex;
          align-items: center;
          justify-content: space-around;
        "
        v-if="!disabled"
      >
        <div class="tICade">
          <div class="TIClass" style="background: #fff"></div>
          <span>未答</span>
        </div>
        <div class="tICade">
          <div class="TIClass" style="background: #7ed321"></div>
          <span>已答</span>
        </div>
        <div class="tICade">
          <div class="TIClass" style="background: #175dff"></div>
          <span>当前</span>
        </div>
      </div>
      <div
        style="
          width: 100%;
          height: 3.19rem;
          display: flex;
          align-items: center;
          justify-content: space-around;
        "
        v-else
      >
        <div class="tICade">
          <div class="TIClass" style="background: #fff"></div>
          <span>未答</span>
        </div>
        <div class="tICade">
          <div class="TIClass" style="background: #7ed321"></div>
          <span>正确</span>
        </div>
        <div class="tICade">
          <div class="TIClass" style="background: #f33e34"></div>
          <span>错误</span>
        </div>
      </div>
      <div class="content" id="content" v-if="!isctlist">
        <div v-for="(it, index) in TiType" :key="index">
          <div v-if="it.length != 0">
            <span class="TI_title">{{ it[0] ? it[0].qtype : "" }}题 </span>
          </div>
          <van-row>
            <van-col span="4" v-for="item in it" :key="item.tixu">
              <div
                class="XH_box"
                :style="item.type"
                @click="changeTi(item)"
                :id="'Ti-' + item.tixu"
              >
                {{ item.tixu }}
              </div>
            </van-col>
          </van-row>
        </div>
      </div>
      <div class="content" id="content" v-else>
        <van-row>
          <van-col span="4" v-for="item in Ti" :key="item.tixu">
            <div
              class="XH_box"
              :style="item.type"
              @click="changeTi(item)"
              :id="'Ti-' + item.tixu"
            >
              {{ item.tixu }}
            </div>
          </van-col>
        </van-row>
      </div>
    </van-action-sheet>
    <!-- <van-dialog v-model="dialogVisible" title="我的成绩" show-cancel-button>
            
        </van-dialog> -->
    <div
      style="position: absolute; top: 0; right: 0; height: 100vh; width: 100vw;background: #eee;"
      v-if="disFace"
    >
      <face :comments="true" :show.sync="disFace" :type="titleName=='正式考试'?'zsface':titleName=='模拟考试'?'mkface':!titleName?'zxface':''"></face>
    </div>
  </div>
</template>

<script>
import { ImagePreview } from "vant";
import {
  exerAdd,
  exerCollect,
  exerdelCollect,
  mockAdd,
  examAdd,
  mockcollect,
  mockcancelcollect,
  resetwrong,
  exerList,
  zujuandone,
  zujuandoneexam,
  removeWrong,
} from "@/api/admin.js";
import router from "@/router";
import {
  setTi,
  getTi,
  delTi,
  getExectSetting,
  getapplyid,
  getAdminToken,
  getAdminUserId,
} from "@/utils/auth.js";
import face from "@/components/Face/photo.vue";
import { mapGetters } from "vuex";
// import ajax from 'ajax'
export default {
  name: "examexam",
  components: { face },
  data() {
    return {
      nowQuestion: "",
      titleName: this.$route.query.titleName,
      usererror: this.$route.query.usererror, //首页错题集进来的
      show: false,
      radio: "1",
      DQTI: {},
      Ti: [], //所有试题
      DXTi: [], //单选题
      MOTi: [], //单选题
      PDTi: [], //判断题
      ALTi: [], //案例题
      TiType: [], //试题题型 单选题  单选题  判断题
      TIXU: 1,
      Tistyle: {
        background: "#fff",
        color: "#666",
      }, //未答题样式
      DQTistyle: {
        background: "#175DFF",
        color: "#FFF",
      }, //当前题样式
      YDTistyle: {
        background: "#7ED321",
        color: "#FFF",
      }, //已答题题样式
      DCTistyle: {
        background: "#F33E34",
        color: "#FFF",
      }, //答错题样式
      DDTistyle: {
        background: "#7ED321",
        color: "#FFF",
      }, //答对题样式
      daan: "",
      checkList: [], //多选的vuelue
      Current: {
        mame: "1",
        stem: "",
        tiList: [],
        answer: "",
        analysis: "",
        id: "",
        qtype: "",
      },
      commitData: [],
      downdisabled: true,
      enddisabled: false,
      isDaAn: false, //进入时是否展示答案
      Collectionlist: [],
      isYes: false, //默认不收藏
      jjtc: true,
      subjectid: this.$route.query.subjectid, //专业id
      exerid: this.$route.query.exerid,
      isctlist: this.$route.query.commitData ? true : false,

      //模拟考试 正式考试
      getExectSettingData: getExectSetting()
        ? JSON.parse(getExectSetting())
        : {},
      gz: this.$route.query.gz,
      time: getExectSetting()
        ? Number(JSON.parse(getExectSetting()).考试时长.时长) * 60 * 1000
        : 0,
      NowTime: 0,
      dialogVisible: true,
      correct: 0, //正确题数
      error: 0, //错误题数
      Unanswered: 0, //未答题数
      fraction: 0, //最终得分
      isjiaojuan: true, //如果已经交卷  则为fales
      loading: false,
      disabled: false, //复卷时禁用答题功能
      mockid: this.$route.query.mockid, //模拟考试 试卷id  唯一
      examid: this.$route.query.examid, //正式考试 试卷id  唯一
      form: this.$route.query.form, //模拟考试 重新做题
      errORpass: false, //当前题 答案正确还是错误
      num: 1,
      rengong: this.$route.query.rengong, //人工组卷

      facetimeObj: Object, //人脸验证倒计时对象
      disFace: false,
      beforeUnloadTime: null,
      isEndSendOK: false,
    };
  },
  methods: {
    goFeedback() {
      // const { cache, keys } = this.$bus.$children[0].$refs.currRoutePage;

      this.$router.push({
        name: "feedback",
        params: {
          id: this.Current.id,
          tiList: this.Current.tiList,
          question_info: this.nowQuestion,
        },
      });
    },
    //图片放大
    openImg(img) {
      ImagePreview(img);
    },
    //背题模式
    beiti() {
      this.isDaAn = true;
      this.jjtc = false;
      this.disabled = true;
      this.daanStyle(this.DQTI);
    },
    zuoti() {
      this.isDaAn = false;
      this.jjtc = true;
      this.disabled = false;
    },
    goBack(data) {
      this.$router.push("/home").then(() => {
        this.loading = false;
      });
      // if(){
      // }
    },
    //样式切换
    styleChange(val) {
      this.styleMap();
      this.Ti.map((item) => {
        if (Number(item.name) == val) {
          item.type = this.DQTistyle;
          this.DQTI = item;
          this.funChangeTi(item);
        }
      });
    },
    //点击题号切换试题
    changeTi(item) {
      this.show = false;
      this.DQTI = item;
      this.TIXU = item.name;
      this.funChangeTi(item);
      this.changeClick();
      if (this.TIXU < this.Ti.length) {
        this.downdisabled = true;
      } else {
        this.downdisabled = false;
      }
      this.$forceUpdate();
    },
    swiperleft() {
      this.num++;
      // this.changeClick('end')
    },
    swiperright() {
      this.num--;
      // this.changeClick('add')
    },
    //按钮切换试题
    changeClick(data) {
      this.downdisabled = true;
      this.enddisabled = true;
      this.daan = "";
      if (this.disabled) {
        this.isDaAn = true;
      } else {
        this.isDaAn = false;
      }
      if (this.downdisabled && data == "add") {
        this.TIXU = Number(this.DQTI.name) + 1;
      }
      if (this.downdisabled && data == "end") {
        this.TIXU = Number(this.DQTI.name) - 1;
      }
      if (this.Ti.length <= Number(this.TIXU)) {
        this.downdisabled = false;
      }
      if (Number(this.TIXU) <= 1) {
        this.enddisabled = false;
      }

      this.$forceUpdate();
    },
    //试题信息  切换试题时  触发此函数
    funChangeTi(item) {
      this.nowQuestion = JSON.stringify(item);

      let Arr = [];
      Arr.push(
        {
          cred: "A",
          content: item.a,
          content_img: item.a_img,
        },
        {
          cred: "B",
          content: item.b,
          content_img: item.b_img,
        },
        {
          cred: "C",
          content: item.c,
          content_img: item.c_img,
        },
        {
          cred: "D",
          content: item.d,
          content_img: item.d_img,
        },
        {
          cred: "E",
          content: item.e,
          content_img: item.e_img,
        },
        {
          cred: "F",
          content: item.f,
          content_img: item.f_img,
        }
      );
      if (item.children) {
        item.children.map((el) => {
          // if(!el.checkList||el.checkList.length==0){
          //   el.checkList=[]
          // }
          if (!el.childrenti) {
            el.childrenti = [
              {
                cred: "A",
                content: el.a,
                content_img: el.a_img,
              },
              {
                cred: "B",
                content: el.b,
                content_img: el.b_img,
              },
              {
                cred: "C",
                content: el.c,
                content_img: el.c_img,
              },
              {
                cred: "D",
                content: el.d,
                content_img: el.d_img,
              },
              {
                cred: "E",
                content: el.e,
                content_img: el.e_img,
              },
              {
                cred: "F",
                content: el.f,
                content_img: el.f_img,
              },
            ];
          }
        });
      }
      this.Current = {
        name: item.name,
        stem: item.stem,
        tiList: Arr,
        answer: item.answer,
        analysis: item.analysis,
        id: item.id,
        qtype: item.qtype,
        stem_img: item.stem_img,
        children: item.children ? item.children : null,
      };
      //每次切换试题都要重新填写用户相对应的答案
      this.daan = "";
      this.checkList = [];
      this.commitData.map((ite) => {
        if (this.Current.qtype != "案例") {
          if (ite.questionid == item.id) {
            this.daan = ite.uanswer;
            this.checkList = ite.uanswer.split("");
          }
        } else {
          if (ite.pid == item.id) {
            item.children.map((el) => {
              if (el.qtype != "多选") {
                // el.daan=el.uanswer
              } else {
                el.checkList = el.uanswer.split("");
              }
            });
          }
        }
      });
      this.isYes = item.collected ? item.collected : false;
      // this.isYes = false;
      this.Collectionlist.map((itemA) => {
        if (itemA.questionid == item.id) {
          this.isYes = true;
        }
      });
      let isshow = this.$route.query.daan == "显示";

      if (this.daan && isshow) {
        this.isDaAn = true;
      }
      if (this.disabled) {
        this.daanStyle(item);
        this.isDaAn = true;
      }
    },
    danChange(data, text) {
      this.$forceUpdate();
      let obj = JSON.parse(JSON.stringify(data));
      if (
        this.$route.query.daan == "显示" &&
        this.Current.qtype == "多选" &&
        text != "commit"
      ) {

      } else {
        let isshow = this.$route.query.daan == "显示";
        let answer = obj.answer
        if (data.qtype == "多选") {
          this.daan = JSON.parse(JSON.stringify(this.checkList))
            .sort()
            .join("");
            answer = obj.answer.split('').sort().join('')
        }
        let scored; //是否正确   对 1 错 0
        
       
        if (answer == this.daan) {
          scored = 1;
        } else {
          scored = 0;
        }
        if (this.Current.qtype == "案例" && data.qtype == "多选") {
          obj.uanswer = obj.checkList.sort().join("");
        }
        if (this.Current.qtype == "案例") {
          if (data.answer == obj.uanswer) {
            scored = 1;
          } else {
            scored = 0;
          }
        }
        if ((this.daan || obj.uanswer) && isshow) {
          this.isDaAn = true;
        }
        if (this.disabled) {
          this.isDaAn = true;
        }
        var isyes = false;
        this.commitData.map((item) => {
          if (this.commitData.length == 0 || item.questionid == data.id) {
            isyes = true;
            item.pid = obj.pid ? obj.pid : null;
            item.uanswer =
              this.Current.qtype == "案例" ? obj.uanswer : this.daan;
            item.scored = scored;
            item.qtype = data.qtype;
          }
        });
        if (!isyes && (this.daan || obj.uanswer)) {
          this.commitData.push({
            questionid: data.id,
            uanswer: this.Current.qtype == "案例" ? obj.uanswer : this.daan,
            scored,
            qtype: data.qtype,
            pid: obj.pid ? obj.pid : null,
          });
        }
      }
    },
    //收藏 取消收藏
    CollectionClick(data) {
      var isyes = false;
      this.isYes = !this.isYes;
      this.Collectionlist.map((item, index) => {
        if (this.Collectionlist.length == 0 || item.questionid == data.id) {
          isyes = true;
          delete this.Collectionlist[index];
          if (!this.titleName) {
            exerdelCollect({
              subjectid: this.subjectid,
              questionid: data.id,
              applyid: getapplyid(),
            }).then((res) => {
              if (res.code == 200) {
                this.$toast.success("取消成功");
              } else {
                this.$toast.fail(res.msg);
              }
            });
          } else if (this.titleName == "模拟考试") {
            mockcancelcollect({
              subjectid: this.subjectid,
              questionid: data.id,
              zujuan: this.rengong == "1" ? 1 : "",
              applyid: getapplyid(),
            }).then((res) => {
              if (res.code == 200) {
                this.$toast.success("取消成功");
              } else {
                this.$toast.fail(res.msg);
              }
            });
          }
        }
      });
      if (!isyes) {
        this.Collectionlist.push({ questionid: data.id, isYes: true });
        if (!this.titleName) {
          exerCollect({
            subjectid: this.subjectid,
            questionid: data.id,
            applyid: getapplyid(),
          }).then((res) => {
            if (res.code == 200) {
              this.$toast.success("收藏成功");
            } else {
              this.$toast.fail(res.msg);
            }
          });
        } else if (this.titleName == "模拟考试") {
          mockcollect({
            subjectid: this.subjectid,
            questionid: data.id,
            zujuan: this.rengong == "1" ? 1 : "",
            applyid: getapplyid(),
          }).then((res) => {
            if (res.code == 200) {
              this.$toast.success("收藏成功");
            } else {
              this.$toast.fail(res.msg);
            }
          });
        }
      }
    },
    //处理函数
    formattingData(arr, group_key) {
      let map = {};
      let res = [];
      // 循环需要筛选的数组
      for (let i = 0; i < arr.length; i++) {
        let ai = arr[i];
        // 将需要筛选的属性的值作为新对象的键，并且判断是否已经存在
        if (!map[ai[group_key]]) {
          // 不存在的话就在map对象中创建一个属性的值作为键名，键值为空数组的新对象，并且把arr[i]放入
          map[ai[group_key]] = [ai];
        } else {
          // 如果已经存在就直接把arr[i]放入
          map[ai[group_key]].push(ai);
        }
      }
      // 循环后对map进行处理生成分组的数组
      // Object.keys(map).forEach((key) => {
      // res.push({
      //     [group_key]: key,
      //     list: map[key],
      // });
      // });

      return map;
    },
    //提交
    commit() {
      this.jjtc = false;
      if (!this.titleName) {
        this.loading = true;
        if (this.commitData.length == 0) return this.goBack();
        exerAdd(this.exerid, {
          exerlog: JSON.stringify(this.commitData),
          progress: this.DQTI.id,
        }).then((res) => {
          //  this.loading = false
          if (res.code == 200) {
            // this.$toast.success("提交成功");
          } else {
            this.$toast.fail("答题记录提交失败");
          }
          this.goBack();
        });
        // if (this.commitData.length > 0) {
        // } else {
        //   this.$toast.fail("本次答题为空,将不保存答题记录");
        //   this.goBack()
        // }
      } else {
        let msg = "";
        if (this.commitData.length < this.Ti.length) {
          msg = "您还没有做完，确定要交卷吗";
        } else {
          msg = "确定要交卷吗";
        }
        this.$dialog
          .confirm({
            title: "提示",
            message: msg,
            showCancelButton: true,
          })
          .then(() => {
            this.correct = 0;
            this.error = 0;
            let Dfen = 0; //单选做对题数
            let Pfen = 0; //判断做对题数
            let Mfen = 0; //多选做对题数
            let AfenA = 0; //案例做错题数
            let AfenZ = 0; //案例题总数
            if (this.usererror != "错题集") {
              this.$refs.time.pause();
            }
            if (this.ALTi.length != 0 && this.commitData.length != 0) {
              this.Ti.map((item) => {
                if (item.qtype == "案例") {
                  AfenZ++;
                  let isyes = false;
                  this.formattingData(this.commitData, "pid")[item.id] &&
                    this.formattingData(this.commitData, "pid")[item.id].map(
                      (el) => {
                        if (!Boolean(item.scored)) {
                          isyes = true;
                        }
                      }
                    );
                  if (isyes) {
                    AfenA++;
                  }
                }
              });
            }
            this.commitData.map((item) => {
              if (!item.pid) {
                if (Boolean(item.scored)) {
                  this.correct++;
                  if (item.uanswer == "正确" || item.uanswer == "错误") {
                    Pfen++;
                  } else if (item.uanswer.length > 1) {
                    Mfen++;
                  } else {
                    Dfen++;
                  }
                } else {
                  this.error++;
                }
              }
            });

            let Dfens = 0;
            let Mfens = 0;
            let Pfens = 0;
            let Afens = 0;
            if (this.ALTi.length != 0) {
              Dfens = Dfen * this.getExectSettingData.试题分布.单选.分数; //单选得分
              Mfens = Mfen * this.getExectSettingData.试题分布.多选.分数; //多选得分
              Pfens = Pfen * this.getExectSettingData.试题分布.判断.分数; //判断得分
              Afens =
                (AfenZ - AfenA) * this.getExectSettingData.试题分布.案例.分数; //案例得分
              this.fraction = Dfens + Mfens + Pfens + Afens; //总分
              const map = new Map();
              this.Unanswered =
                this.Ti.length -
                this.commitData.filter((item) => {
                  return !map.has(item.pid) && map.set(item.pid, 1);
                }).length;
              this.error += AfenA;
              this.correct = AfenZ - AfenA;
            } else {
              Dfens = Dfen * this.getExectSettingData.试题分布.单选.分数; //单选得分
              Mfens = Mfen * this.getExectSettingData.试题分布.多选.分数; //多选得分
              Pfens = Pfen * this.getExectSettingData.试题分布.判断.分数; //判断得分
              this.fraction = Dfens + Mfens + Pfens; //总分
              this.Unanswered = this.Ti.length - this.commitData.length; //未作题
            }
            this.$forceUpdate();
            if (this.commitData.length > 0) {
              this.loading = true;
              this.isjiaojuan = false;
              if (this.titleName == "模拟考试" && !this.usererror) {
                let obj = {
                  mockid: this.mockid,
                  gz: this.gz,
                };
                if (this.rengong == "1") {
                  zujuandone({
                    mockid: this.mockid,
                    mocklog: JSON.stringify(this.commitData),
                    use_time: this.NowTime,
                  }).then((res) => {
                    this.loading = false;
                    if (res.code == 200) {
                      this.$router.push({
                        path: "/result",
                        query: {
                          Unanswered: res.data.undo,
                          correct: res.data.done - res.data.wrong,
                          error: res.data.wrong,
                          fraction: res.data.score,
                          commitData: JSON.stringify(this.commitData),
                          titleName: this.titleName,
                          subjectid: this.subjectid,
                        },
                      });
                    }
                  });
                } else {
                  mockAdd(obj, {
                    mocklog: JSON.stringify(this.commitData),
                    use_time: this.NowTime,
                  }).then((res) => {
                    this.loading = false;
                    if (res.code == 200) {
                      this.$router.push({
                        path: "/result",
                        query: {
                          Unanswered: res.data.undo,
                          correct: res.data.done - res.data.wrong,
                          error: res.data.wrong,
                          fraction: res.data.score,
                          commitData: JSON.stringify(this.commitData),
                          titleName: this.titleName,
                          subjectid: this.subjectid,
                        },
                      });
                    }
                  });
                }
              } else if (this.titleName == "正式考试") {
                let obj = {
                  examid: this.examid,
                  gz: this.gz,
                };
                if (this.rengong == "1") {
                  zujuandoneexam({
                    examid: this.examid,
                    examlog: JSON.stringify(this.commitData),
                    use_time: this.NowTime,
                  }).then((res) => {
                    this.loading = false;
                    if (res.code == 200) {
                      this.$router.push({
                        path: "/result",
                        query: {
                          Unanswered: res.data.undo,
                          correct: res.data.done - res.data.wrong,
                          error: res.data.wrong,
                          fraction: res.data.score,
                          commitData: JSON.stringify(this.commitData),
                          titleName: this.titleName,
                          subjectid: this.subjectid,
                        },
                      });
                    }
                  });
                } else {
                  examAdd(obj, {
                    examlog: JSON.stringify(this.commitData),
                    use_time: this.NowTime,
                  }).then((res) => {
                    this.loading = false;
                    if (res.code == 200) {
                      this.$router.push({
                        path: "/result",
                        query: {
                          Unanswered: res.data.undo,
                          correct: res.data.done - res.data.wrong,
                          error: res.data.wrong,
                          fraction: res.data.score,
                          commitData: JSON.stringify(this.commitData),
                          titleName: this.titleName,
                          subjectid: this.subjectid,
                        },
                      });
                    }
                  });
                }
              } else if (this.usererror == "错题集") {
                resetwrong({
                  qlist: JSON.stringify(this.commitData),
                  subjectid: this.subjectid,
                  applyid: getapplyid(),
                }).then((res) => {
                  this.loading = false;
                  if (res.code == 200) {
                    this.$router.push({
                      path: "/result",
                      query: {
                        Unanswered: this.Unanswered,
                        correct: this.correct,
                        error: this.error,
                        fraction: this.fraction,
                        commitData: JSON.stringify(this.commitData),
                        titleName: this.titleName,
                        usererror: this.usererror,
                        subjectid: this.subjectid,
                      },
                    });
                  }
                });
              } else if (this.usererror == "收藏") {
                this.isjiaojuan = false;
                this.$router.push({
                  path: "/result",
                  query: {
                    Unanswered: this.Unanswered,
                    correct: this.correct,
                    error: this.error,
                    fraction: this.fraction,
                    commitData: JSON.stringify(this.commitData),
                    titleName: this.titleName,
                    usererror: this.usererror,
                    subjectid: this.subjectid,
                  },
                });
              }
            } else {
              this.isjiaojuan = false;
              this.$router.push({
                path: "/result",
                query: {
                  Unanswered: this.Unanswered,
                  correct: this.correct,
                  error: this.error,
                  fraction: this.fraction,
                  commitData: JSON.stringify(this.commitData),
                  titleName: this.titleName,
                  usererror: this.usererror,
                  subjectid: this.subjectid,
                },
              });
            }
          });
      }
    },
    //重做
    again() {
      // let obj={
      //   subjectid: this.subjectid,
      //   gz:this.gz,

      // }
      this.$dialog
        .confirm({
          title: "提示",
          message:
            "点击确定后，试题将重新开始，您之前的答案将会清除，是否重新做题",
          showCancelButton: true,
        })
        .then(() => {
          let obj = JSON.parse(this.form);
          obj.restart = 1;
          this.loading = true;
          exerList(obj).then((res) => {
            this.loading = false;
            if (res.code == 200) {
              this.exerid = res.data.exerid;
              this.$toast.success("重置成功");
              this.disabled = false;
              this.isDaAn = false;
              this.jjtc = true;
              this.TIXU = 1;
              this.$store.commit("SET_TI", res.data.list);
              this.$route.query.progress = 0;
              this.creatFunction(); //重新初始化试题
              this.$forceUpdate();
              // location.reload();
            }
          });
        });
    },

    //模拟考试
    //时间
    timeChange(val) {
      if (this.$route.query.examTime) {
        if (
          Number(this.$route.query.examTime) * 1000 >=
          Number(JSON.parse(getExectSetting()).考试时长.时长) * 60 * 1000
        ) {
          this.NowTime =
            Number(JSON.parse(getExectSetting()).考试时长.时长) * 60 -
            val.hours * 3600 -
            val.minutes * 60 -
            val.seconds;
        } else {
          this.NowTime =
            Number(this.$route.query.examTime) -
            val.hours * 3600 -
            val.minutes * 60 -
            val.seconds;
        }
      } else {
        this.NowTime =
          Number(JSON.parse(getExectSetting()).考试时长.时长) * 60 -
          val.hours * 3600 -
          val.minutes * 60 -
          val.seconds;
      }
    },
    //时间结束
    finishTime() {
      //时间结束  自动交卷
      this.ApiJJ();
    },
    //交卷接口  模拟考试
    ApiJJ() {
      this.jjtc = false;
      if (this.usererror != "错题集") {
        this.$refs.time.pause();
      }
      if (this.titleName == "模拟考试") {
        let obj = {
          mockid: this.mockid,
          gz: this.gz,
        };
        if (this.commitData.length > 0) {
          if (this.rengong == "1") {
            zujuandone({
              mockid: this.mockid,
              mocklog: JSON.stringify(this.commitData),
              use_time: this.NowTime,
            }).then((res) => {
              if (res.code == 200) {
                this.$router.push({
                  path: "/result",
                  query: {
                    Unanswered: res.data.undo,
                    correct: res.data.done - res.data.wrong,
                    error: res.data.wrong,
                    fraction: res.data.score,
                    commitData: JSON.stringify(this.commitData),
                    titleName: this.titleName,
                    subjectid: this.subjectid,
                  },
                });
              }
            });
          } else {
            mockAdd(obj, {
              mocklog: JSON.stringify(this.commitData),
              use_time: this.NowTime,
            }).then((res) => {
              if (res.code == 200) {
                this.$router.push({
                  path: "/result",
                  query: {
                    Unanswered: res.data.undo,
                    correct: res.data.done - res.data.wrong,
                    error: res.data.wrong,
                    fraction: res.data.score,
                    commitData: JSON.stringify(this.commitData),
                    titleName: this.titleName,
                    subjectid: this.subjectid,
                  },
                });
              }
            });
          }
        }
      } else if (this.titleName == "正式考试") {
        let obj = {
          examid: this.examid,
          gz: this.gz,
        };
        if (this.commitData.length > 0) {
          if (this.rengong == "1") {
            zujuandoneexam({
              examid: this.examid,
              examlog: JSON.stringify(this.commitData),
              use_time: this.NowTime,
            }).then((res) => {
              if (res.code == 200) {
                delisfacetimezsface();
                this.$router.push({
                  path: "/result",
                  query: {
                    Unanswered: res.data.undo,
                    correct: res.data.done - res.data.wrong,
                    error: res.data.wrong,
                    fraction: res.data.score,
                    commitData: JSON.stringify(this.commitData),
                    titleName: this.titleName,
                    subjectid: this.subjectid,
                  },
                });
              }
            });
            return "/index/exam/zujuandone";
          } else {
            examAdd(obj, {
              examlog: JSON.stringify(this.commitData),
              use_time: this.NowTime,
            }).then((res) => {
              if (res.code == 200) {
                this.$router.push({
                  path: "/result",
                  query: {
                    Unanswered: res.data.undo,
                    correct: res.data.done - res.data.wrong,
                    error: res.data.wrong,
                    fraction: res.data.score,
                    commitData: JSON.stringify(this.commitData),
                    titleName: this.titleName,
                    subjectid: this.subjectid,
                  },
                });
              }
            });
            return "/index/mock/done?examid=" + this.examid + "&gz=" + this.gz;
          }
        }
      }
    },
    //复卷
    rewinding() {
      this.disabled = true;
      this.isDaAn = true;
      this.isjiaojuan = false;
      this.jjtc = false;
      // this.styleMap()
    },
    //答案展示样式
    daanStyle(val) {
      this.commitData.map((item) => {
        if (item.questionid == val.id && item.uanswer) {
          this.errORpass = Boolean(item.scored);
        }
      });
    },
    //默认样式改变
    styleMap() {
      this.Ti.map((item) => {
        item.type = this.Tistyle;
        this.commitData.map((element) => {
          if (item.id == element.questionid) {
            if (!this.disabled) {
              item.type = this.YDTistyle;
            } else {
              if (item.id == element.questionid) {
                if (Boolean(element.scored)) {
                  item.type = this.DDTistyle;
                } else {
                  item.type = this.DCTistyle;
                }
              } else {
                item.type = this.DQTistyle;
              }
            }
          }
        });
      });
    },
    //试题初始化调用
    creatFunction() {
      this.DXTi = [];
      this.MOTi = [];
      this.PDTi = [];
      this.ALTi = [];
      this.TIXU = 1;
      this.commitData = [];
      this.TiType = [];
      this.daan = "";
      // this.Ti.map((item,index)=>{
      //     item.name = index+1 //加入题序
      //     if(item.uanswer){
      //         this.commitData.push({questionid:item.id,uanswer:item.uanswer,scored:item.scored})
      //         this.TIXU=item.name
      //     }
      //     if(item.qtype=='单选'){
      //         this.DXTi.push(item)
      //     }
      //     if(item.qtype=='多选'){
      //         this.MOTi.push(item)
      //     }
      //     if(item.qtype=='判断'){
      //         this.PDTi.push(item)
      //     }
      // })
      let arr = getTi();
      arr.map((item, index) => {
        if (item.qtype == "单选") {
          item.tiTY = 1;
          this.DXTi.push(item);
        }
        if (item.qtype == "多选") {
          item.tiTY = 2;
          this.MOTi.push(item);
        }
        if (item.qtype == "判断") {
          item.tiTY = 3;
          this.PDTi.push(item);
        }
        if (item.qtype == "案例") {
          item.tiTY = 4;
          this.ALTi.push(item);
        }
      });
      this.Ti = arr.sort((a, b) => {
        return a.tiTY - b.tiTY;
      });

      this.Ti.map((item, index) => {
        item.name = index + 1; //加入题序
        if (item.qtype == "案例" && item.children) {
          item.children.map((el) => {
            if (el.uanswer) {
              this.commitData.push({
                questionid: el.id,
                uanswer: el.uanswer,
                scored: el.scored,
                qtype: el.qtype,
                pid: item.id,
              });
            }
          });
        } else {
          if (item.uanswer) {
            this.commitData.push({
              questionid: item.id,
              uanswer: item.uanswer,
              scored: item.scored,
            });
          }
        }

        if (
          this.$route.query.progress &&
          this.$route.query.progress == item.id
        ) {
          this.TIXU = item.name;
        }
        // if(this.$route.query.progress==0){
        //   if (item.uanswer) {
        //     this.TIXU = item.name;
        //   }
        // }
      });
      this.$forceUpdate()
      let A = true;
      let B = true;
      let C = true;
      let D = true;
      if (this.DXTi.length != 0) {
        this.DXTi.map((item, index) => {
          item.tixu = index + 1;
        });
        this.DXTi.map((item) => {
          if (!item.qtype) {
          }
        });
      } else {
        A = false;
      }
      if (this.MOTi.length != 0) {
        this.MOTi.map((item, index) => {
          item.tixu = this.DXTi.length + index + 1;
        });
      } else {
        B = false;
      }
      if (this.PDTi.length != 0) {
        this.PDTi.map((item, index) => {
          item.tixu = this.MOTi.length + this.DXTi.length + index + 1;
        });
        this.PDTi.map((item) => {
          if (!item.qtype) {
          }
        });
      } else {
        C = false;
      }
      if (this.ALTi.length != 0) {
        this.ALTi.map((item, index) => {
          item.tixu =
            this.MOTi.length + this.DXTi.length + this.PDTi.length + index + 1;
        });
        this.ALTi.map((item) => {
          if (!item.qtype) {
          }
        });
      } else {
        D = false;
      }
      this.TiType.push(this.DXTi, this.MOTi, this.PDTi, this.ALTi);
      let sum = 1;
      this.TiType.map((item) => {
        if (item.length != 0) {
          item[0].sum = sum++;
        }
      });
      if (A) {
        this.DQTI = this.TiType[0][0];
      } else if (B) {
        this.DQTI = this.TiType[1][0];
      } else if (C) {
        this.DQTI = this.TiType[2][0];
      } else if (D) {
        this.DQTI = this.TiType[3][0];
      }
      if (this.commitData.length != 0) {
        this.daan = this.commitData[this.commitData.length - 1].uanswer;
      }

      let TI = JSON.parse(JSON.stringify(this.Ti));
      if (Boolean(this.$route.query.commitData)) {
        this.commitData = JSON.parse(this.$route.query.commitData);
        this.rewinding();
        this.daanStyle(this.Ti[0]);
        if (this.$route.query.error) {
          this.Ti = [];
          this.commitData
            .filter((item) => {
              return !Boolean(item.scored);
            })
            .map((item, index) => {
              TI.map((it) => {
                if (item.pid) {
                  if (it.id == item.pid) {
                    let isY = true;
                    this.Ti.map((el) => {
                      if (it.id == el.id) {
                        isY = false;
                      }
                    });
                    if (it.children) {
                      it.children.map((el) => {
                        if (el.id == item.questionid) {
                          if (el.qtype != "多选") {
                            el.uanswer = item.uanswer;
                          } else {
                            el.checkList = item.uanswer.split("");
                          }
                        }
                        el.noerror = false;
                        if (!el.uanswer && !el.checkList) {
                          el.noerror = true;
                          // if(el.qtype!='多选'){
                          //   el.uanswer=el.answer
                          // }else{
                          //   el.checkList=el.answer.split('')
                          // }
                        }
                      });
                    }
                    if (isY) {
                      it.name = index + 1; //加入题序
                      this.Ti.push(it);
                    }
                  }
                } else {
                  if (it.id == item.questionid) {
                    it.name = index + 1; //加入题序
                    this.Ti.push(it);
                  }
                }
              });
            });
        }
      } else {
        clearTimeout(this.facetimeObj);
        if (
          this.titleName == "正式考试" &&
          this.initObj.is_face &&
          JSON.parse(this.initObj.is_face)[this.gz].zsface == "开启" &&
          Number(JSON.parse(this.initObj.is_face)[this.gz].zsfacetime)
        ) {
          this.facetimeObj = setTimeout(() => {
            this.disFace = true;
          }, JSON.parse(this.initObj.is_face)[this.gz].zsfacetime * 60 * 1000);
        }
      }
      if (this.TIXU == 1) {
        this.enddisabled = false;
        this.downdisabled = true;
      } else if (this.TIXU == this.Ti.length) {
        this.downdisabled = false;
        this.enddisabled = true;
      } else {
        this.enddisabled = true;
        this.downdisabled = true;
      }
      if (this.TIXU == 1 && this.TIXU == this.Ti.length) {
        this.enddisabled = false;
        this.downdisabled = false;
      }
      if (this.gz == "fj") {
        this.rewinding();
        this.TIXU = 1;
      }
      this.styleChange(this.DQTI.tixu);
    },
    //事件监听函数
    // functionAll(){
    //     alert(111111111111111)
    //     if(this.jjtc&&this.commitData.length>0&&!this.titleName){
    //         exerAdd(this.exerid,{exerlog:JSON.stringify(this.commitData)}).then(res=>{
    //         })
    //     }
    //     if(this.titleName=='模拟考试'&&this.jjtc&&this.isjiaojuan){
    //         this.ApiJJ()
    //     }
    // }
    //移出错题库
    delerror(row) {
      removeWrong({
        subjectid: this.subjectid,
        qtype: row.qtype,
        questionid: row.id,
      }).then((res) => {
        if (res.code == 200) {
          this.$toast.success(res.msg);
          var arrI = 0;

          this.Ti.map((item, index) => {
            if (item.id == row.id) {
              this.Ti.splice(index, 1);
              arrI = index;
            }
          });
          if (this.Ti.length == 0) {
            this.$dialog
              .confirm({
                message: "错题已全部移出,点击'确定'按钮退出当前答题界面",
                title: "提示",
                confirmButtonText: "确定",
                showCancelButton: false,
              })
              .then(() => {
                this.goBack();
              })
              .catch(() => {});
          } else {
            setTi(this.Ti);
            this.creatFunction();
          }
          // this.TiType[num].map((item,index)=>{
          //   if(item.id==row.id){
          //     arrI=index
          //   }
          // })
          // this.styleChange(this.TiType[num][arrI+1].name);
          // this.TIXU=this.TiType[num][arrI].name
          // this.funChangeTi(this.TiType[num][arrI])
        } else {
          this.$toast.fail(res.msg);
        }
      });
    },
    //移出收藏
    async delSc(row) {
      // let num = 0;
      // if (row.qtype == "单选") {
      //   num = 0;
      // }
      // if (row.qtype == "多选") {
      //   num = 1;
      // }
      // if (row.qtype == "判断") {
      //   num = 2;
      // }
      let error = "";
      // return
      await mockcancelcollect({
        subjectid: this.subjectid,
        questionid: row.id,
        applyid: getapplyid(),
      }).then((res) => {
        if (res.code == 200) {
          var arrI = 0;

          this.Ti.map((item, index) => {
            if (item.id == row.id) {
              this.Ti.splice(index, 1);
              arrI = index;
            }
          });

          if (this.Ti.length == 0) {
            this.$dialog
              .confirm({
                message: "收藏试题已全部移出,点击'确定'后将退出当前答题界面",
                title: "提示",
                confirmButtonText: "确定",
                showCancelButton: false,
              })
              .then(() => {
                this.goBack();
              })
              .catch(() => {});
          } else {
            setTi(this.Ti);
            this.creatFunction();
          }
        } else {
          error = res.msg;
          // this.$message.error(res.msg);
        }
      });
      await exerdelCollect({
        subjectid: this.subjectid,
        questionid: row.id,
        applyid: getapplyid(),
      }).then((res) => {
        if (res.code == 200) {
          // this.$message.success(res.msg);
          var arrI = 0;
          this.Ti.map((item, index) => {
            if (item.id == row.id) {
              this.Ti.splice(index, 1);
              arrI = index;
            }
          });

          if (this.Ti.length == 0) {
            this.$dialog
              .confirm({
                message: "收藏试题已全部移出,点击'确定'后将退出当前答题界面",
                title: "提示",
                confirmButtonText: "确定",
                showCancelButton: false,
              })
              .then(() => {
                this.goBack();
              })
              .catch(() => {});
          } else {
            setTi(this.Ti);
            this.creatFunction();
          }
        } else {
          error = res.msg;
          // this.$message.error(res.msg);
        }
      });
      // if(error){
      //   this.$message.error(error)
      //   }else{
      //     }
      this.$toast.success("移出成功");
    },
    beforeunloadHandler(e) {
      this.beforeUnloadTime = new Date().getTime();
    },
    unloadHandler(e) {
      // 这里调用时间函数确保记录时间的准确性
      this.gapTime = new Date().getTime() - this.beforeUnloadTime;
      //判断是窗口关闭还是刷新
      if (this.gapTime <= 5) {
        localStorage.setItem("ua", "true");
        ajax({
          url: "/api/demo",
          type: "get",
          async: false, //或false,是否异步
          success: function (res) {
            localStorage.setItem("reqs", JSON.stringify(res));
          },
          error: function (res) {
            localStorage.setItem("reqs", JSON.stringify(res));
          },
        });
      }
    },
    report(e) {
      if (this.isEndSendOK) {
        return;
      }
      this.isEndSendOK = true;
      let url;
      let data;
      if (this.jjtc && !this.titleName && this.commitData.length != 0) {
        url = "/index/exer/done?exerid=" + this.exerid;
        data = {
          exerlog: JSON.stringify(this.commitData),
          progress: this.DQTI.id,
        };
      }
      if (
        this.titleName == "模拟考试" &&
        this.jjtc &&
        this.isjiaojuan &&
        this.usererror != "错题集" &&
        this.usererror != "收藏"
      ) {
        if (this.rengong == "1") {
          url = "/index/mock/zujuandone";
          data = {
            mockid: this.mockid,
            mocklog: JSON.stringify(this.commitData),
            use_time: this.NowTime,
          };
        } else {
          url = "/index/mock/done?mockid=" + this.mockid + "&gz=" + this.gz;
          data = {
            mocklog: JSON.stringify(this.commitData),
            use_time: this.NowTime,
          };
        }
      }
      if (this.jjtc && this.usererror == "错题集") {
        url = "/index/user/resetwrong";
        data = {
          qlist: JSON.stringify(this.commitData),
          subjectid: this.subjectid,
          applyid: getapplyid(),
        };
      }
      localStorage.setItem(
        "examCommit",
        JSON.stringify({
          DateTime: new Date().getTime(),
          examData: data,
          url,
        })
      );
    },
    visility() {
      if (document.visibilityState == "hidden") {
        this.report();
      } else {
        // 如果界面又显示了，说明没有关闭，重置标志位
        this.isEndSendOK = false;
      }
    },
  },
  watch: {
    TIXU(val) {
      this.styleChange(val);
    },
    show(val) {
      if (val) {
        this.$nextTick(() => {
          document.getElementById("rootBox").children[0].scrollTop =
            document.getElementById("Ti-" + this.TIXU).offsetTop; //激活锚点
        });
      }
    },
    // daan(val){
    // }
    disFace(val) {
      this.$nextTick(() => {
        if (val) {
          clearTimeout(this.facetimeObj);
          // this.$refs.time.pause()
        } else {
          if (
            this.initObj.is_face &&
            JSON.parse(this.initObj.is_face)[this.gz].zsface == "开启" &&
            JSON.parse(this.initObj.is_face)[this.gz].zsfacetime
          ) {
            this.facetimeObj = setTimeout(() => {
              this.disFace = true;
            }, JSON.parse(this.initObj.is_face)[this.gz].zsfacetime * 60 * 1000);
          }
          // this.$refs.time.start()
        }
      });
    },
  },
  computed: {
    // ...mapGetters(['Ti']),//所有试题
    qtype: function () {
      return this.Current.qtype;
    },
    ...mapGetters(["initObj"]),
  },
  created() {
    if (!getTi()) {
      this.$router.go(-1);
    }
    if (this.$route.query.examTime) {
      if (
        Number(this.$route.query.examTime) * 1000 >=
        Number(JSON.parse(getExectSetting()).考试时长.时长) * 60 * 1000
      ) {
        this.time =
          Number(JSON.parse(getExectSetting()).考试时长.时长) * 60 * 1000;
      } else {
        this.time = Number(this.$route.query.examTime) * 1000;
      }
    }
    this.creatFunction();
  },
  beforeDestroy() {
    // window.removeEventListener('beforeunload', this.report);
    // window.removeEventListener('pagehide', this.report);
    // window.removeEventListener('unload', this.report);
    // window.removeEventListener('visibilitychange', this.report);
    document.removeEventListener("visibilitychange", this.visility);
    if (this.jjtc && !this.titleName && this.commitData.length != 0) {
      exerAdd(this.exerid, {
        exerlog: JSON.stringify(this.commitData),
        progress: this.DQTI.id,
      }).then((res) => {});
    }
    if (
      this.titleName == "模拟考试" &&
      this.jjtc &&
      this.isjiaojuan &&
      this.usererror != "错题集" &&
      this.usererror != "收藏"
    ) {
      this.ApiJJ();
    }
    if (this.jjtc && this.usererror == "错题集") {
      resetwrong({
        qlist: JSON.stringify(this.commitData),
        subjectid: this.subjectid,
        applyid: getapplyid(),
      }).then((res) => {});
    }
  },
  mounted() {
    // ajax({
    //   url:'https://tjy.taijieyun.com/user/index/mock/zujuandone',
    //   type:'post',
    //   async:false,
    //   data:{
    //     mockid: this.mockid,
    //     mocklog: JSON.stringify(this.commitData),
    //     use_time: this.NowTime,
    //   },
    //   success:function(s){
    //     console.log(s);
    //   },
    //   error:function(e){
    //     console.log(e);
    //   }
    // })

    const { cache, keys } =
      this.$bus.$children[0].$refs.currRoutePage.$options.parent;
    router.beforeEach((to, from, next) => {
      if (
        to.path == "/exam" ||
        to.path == "/feedback" ||
        to.path == "/feedbackList" ||
        to.path == "/feedbackCheck"
      ) {
        next();
      } else {
        for (const i in cache) {
          delete cache[i];
        }

        keys.splice(0, 1);
        new Promise((resolve, reject) => {
          this.$destroy("examexam");
          resolve();
        }).then(() => {
          next();
        });
      }
    });
    // 监听多个事件，做同一个事情，用一个标志位确定是否做过
    // 移动端普遍只支持 pagehide
    // this.isEndSendOK = false
    // window.addEventListener('beforeunload', this.report);
    // window.addEventListener('pagehide', this.report);
    // window.addEventListener('unload', this.report);
    // window.onblur = function (params) {

    // }
    // // IOS14 之前不会冒泡，只能监听document
    // localStorage.removeItem('examCommit')
    document.addEventListener("visibilitychange", this.visility);
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .feedback {
    .van-button__content {
      width: 3.7rem;
      height: 1rem;
      font-size: 0.75rem;
      color: #327bff;
    }
  }
}

//   '\e6a7'  叉号  '\e728'  对号
.video_title {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: #327bff;
  color: #fff;
  height: 2.75rem;

  p {
    margin: 0;
    width: calc(100vw - 64px);
    display: flex;
    justify-content: center;
  }
  .icon {
    font-size: 1.25rem;
  }
}
::v-deep {
  .van-checkbox {
    min-height: 3.2rem;
  }
  .van-radio {
    min-height: 3.2rem;
  }
  .pd {
    display: flex;
    align-items: center;
    .van-radio__icon {
      display: flex;
      align-items: center;
    }
  }
  .van-radio__icon {
    min-height: 2.25rem;
  }
  .van-radio__label {
    font-size: 1rem;
  }
  .van-checkbox__icon {
    min-height: 2.25rem;
  }
  .van-checkbox__label {
    font-size: 1rem;
  }
  .van-checkbox__label--disabled {
    color: #323233;
  }
  .van-radio__label--disabled {
    color: #323233;
  }
  .van-row {
    width: 100%;
  }
  .van-button--small {
    height: auto;
    padding: 0.35rem 0.75rem;
  }
  .van-icon-star:before {
    color: #ff9904;
  }
  // .van-checkbox__icon--checked{
  //     .van-icon-success{
  //         background: #fff;
  //         color:#1989fa;
  //     }
  //     .van-icon-success:before{
  //         content:'';
  //         // width: 5px;
  //         // height: 5px;
  //         // background: #fff;
  //     }
  // }
}
.titleBox {
  span {
    p {
      margin: 0;
      font-size: 0.75rem;
      color: #fff;
      background: #327bff;
      border-top-left-radius: 0.69rem;
      border-bottom-left-radius: 0.69rem;
      border-top-right-radius: 0.69rem;
      margin-right: 0.63rem;
      height: 1.19rem;
      width: 2.64rem;
      text-align: center;
      // display: inline-block;
      float: left;
    }
    font-size: 1.2rem;
  }
}
.button_box {
  margin-top: 1.5rem;
  display: flex;
  #DXcommit {
    background: #fa6400;
    border: #fa6400;
  }
  justify-content: space-around;
  .van-button--normal {
    padding: 0 3.09rem;
  }
}
.foot_box {
  position: fixed;
  bottom: 0;
  background: #fff;
  width: 100%;
  height: 50px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.9rem;
}
.img-icon {
  height: 2.25rem;
  width: 2.25rem;
}
.img-iconA {
  height: 1.8rem;
  width: 1.8rem;
  margin: 0 0.2rem;
}
.content {
  padding: 12px;
  height: 24.6rem;
  .XH_box {
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid #ddd;
    border-radius: 50%;
    color: #666;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .van-col {
    margin-bottom: 0.94rem;
  }
}
.tICade {
  display: flex;
  align-items: center;
}
.TIClass {
  // justify-content: space-around;
  width: 2.5rem;
  height: 2.5rem;
  margin-right: 4px;
  border-radius: 50%;
  border: 1px solid #eee;
}
.daan_box {
  margin-top: 8px;
  padding: 1rem 1.75rem;
  background: #eeeeee;
  font-size: 1rem;
  p {
    margin: 0;
  }
}
.TI_title {
  display: flex;
  margin-bottom: 1.7vh;
  font-size: 0.8rem;
  font-weight: 600;
}
</style>
